package com.step.sprite;

import javax.microedition.khronos.opengles.GL10;

import com.step.graphic.Texture;
import com.step.mesh.Mesh;
import com.step.sprite.animation.AnimationMd2;
import com.step.sprite.animation.KeyFrameMd2;

/**
 * 三维MD2动画精灵
 * @author heop
 *
 */
public class Md2Sprite extends Sprite3D{
	AnimationMd2 animation;
	
	public Md2Sprite(Mesh mesh, KeyFrameMd2[] frames,	Texture texture) {
		super(mesh, texture);
		this.animation = new AnimationMd2(frames);
	}
	
	public Md2Sprite(Mesh mesh, AnimationMd2 animation, Texture texture){
		super(mesh,texture);
		this.animation = animation;
	}

	public void draw(GL10 gl) {
		super.draw(gl);
		this.animation.update();

		mesh.getNormalBuffer().overwrite(animation.getNormals());
		mesh.getPositionBuffer().overwrite(animation.getVertices());
	}
	
	public Sprite3D clone(boolean cloneData)
	{		
		Md2Sprite clone = new Md2Sprite(mesh.clone(), animation, texture);
		return clone;
	}
	
	public AnimationMd2 getAnimation(){
		return animation;
	}
}
